Skip to content

SwiftExtract: fix private(set) being ignored for variables with explicit accessors - #908

Merged
ktoso merged 1 commit into
swiftlang:mainfrom
tirdesh:tirdesh/fix-private-set-explicit-accessors
Sep 5, 2026
Merged

SwiftExtract: fix private(set) being ignored for variables with explicit accessors#908
ktoso merged 1 commit into
swiftlang:mainfrom
tirdesh:tirdesh/fix-private-set-explicit-accessors

Conversation

@tirdesh

@tirdesh tirdesh commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #535.

supportedAccessorKinds(binding:minimumAccessLevel:) returned early on
binding.accessorBlock before it reached the private(set) check, so a variable that both
restricts its setter's access level and spells out its accessors explicitly got a setter
binding emitted for a setter it cannot call:

error: cannot assign to property: 'bar' setter is inaccessible
 17 | public func swiftjava_MySwiftLibrary_Foo_bar$set(_ newValue: UnsafePointer<Int8>, _ self: UnsafeRawPointer) {
 18 |   self.assumingMemoryBound(to: Foo.self).pointee.bar = String(cString: newValue)

Moving the modifier check above the accessor block fixes it. The existing
variable_int_privateSet test already covers public private(set) var without an accessor
block, which is why this only shows up when the accessors are written out; the new test
covers that case.

swift test passes, 670 tests in 89 suites. The new test fails before the change and passes
after it.

Not changed here

Subscripts have the same problem by a different path. SwiftAnalysisVisitor.visit(subscriptDecl:)
calls the no-argument accessorBlock.supportedAccessorKinds(), which never consults
minimumAccessLevel, so public private(set) subscript still emits a $set binding. I kept
this PR to the variable case. Happy to fold the subscript fix in here or open a separate
issue for it, whichever you prefer.

…cit accessors

supportedAccessorKinds(binding:minimumAccessLevel:) returned on the accessor
block before it checked the private(set) modifier, so a variable that both
restricts its setter's access level and spells out its accessors got a setter
binding emitted for an inaccessible setter.
@tirdesh
tirdesh requested a review from ktoso as a code owner September 2, 2026 07:14

@ktoso ktoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you

@tirdesh

tirdesh commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@ktoso thanks for the review, lmk if anything else is needed here

@ktoso
ktoso merged commit 0cd903f into swiftlang:main Sep 5, 2026
83 of 84 checks passed
@ktoso

ktoso commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Thank you, will include this in the 0.6.0 now :)

@ktoso ktoso mentioned this pull request Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"public private(set) var" pattern fails to compile

2 participants